#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
try:
    li=[1,2,3]
    li[10]
    dic={1:2}
    dic["ddd"]
except IndexError,e:
    #如果逻辑代码块出现index错误
    print "索引错误:",e
except KeyError,e:
    #如果逻辑代码块出现key错误
    print "键错误:",e
except Exception,e:
    print "错误"

try:
    pass    # 主代码块
except KeyError,e:
    pass    # 特定异常时，执行该块
except Exception,e:
    pass    # 全局异常，前面未被捕获，它进行捕获，特定异常是Exception的派生类。
else:
    pass    # 主代码块执行完，执行该代码块
finally:
    pass    # 无论异常与否，最终执行该代码块


try:
    raise Exception('自定义错误')
except Exception,e:
    print e         #e是对象
'''

class MyException(Exception):  #类似于IndexException
    def __init__(self, msg):
        self.message = msg
    def __str__(self):
        return self.message
try:
    raise MyException('我的异常')
except MyException,e:
    print e

# assert 条件
assert 1 == 1
assert 1 == 2